<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

	public function __construct(){
		if(!isset($_SESSION)): session_start(); endif;
		parent::__construct();

	}

	public function index()
	{
		$data['title'] = 'My Life My Eulogy - Administration';
		$this->load->view('admin/login', $data);
	}

	function validate_credentials(){
		$this->load->model('admin_users_model');
		$user = $this->admin_users_model->validate();
		if($user){
			$data = array('' .
					'email' => $this->input->post('email'),
					'is_logged_in' => TRUE,
					'userid' => $user['userid']
					);

			//$this->session->set_userdata($data);
			$_SESSION['admin_details'] = $data;
			redirect('admin/dashboard', $data);
		}
		else{
			$this->message->set('error','Username and Password do not match.');
			$this->index();
		}
	}

	function logout(){
		if( session_destroy() ){
			$this->index();
		}else exit('wala');

	}
}
